import requests

from wass.settings import IPFW_API_URL


def request_url(url, method, data):
    try:
        if method == "post":
            requests.post(url=url, json=data, timeout=180)
        elif method == "delete":
            requests.delete(url=url, json=data, timeout=180)
    except Exception:
        raise ValueError("系统错误, 设置ip黑白名单失败")


def notify_engine(flag):
    data = {"block": flag}
    try:
        request_url(IPFW_API_URL + '/v1/block', "post", data=data)
    except Exception:
        raise ValueError("系统错误, 切换失败")
